/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.manager;

import java.util.ArrayList;
import java.util.List;

import com.jl.tools.stkeditor.exception.DataNotMatchCodingScheamException;
import com.jl.tools.stkeditor.generate.Code;

/**
 *
 * @author LuHongjun
 */
public class Group {

    /**
     * store the data in one group
     */
    private final List<LineInfo> oneLineList = new ArrayList<LineInfo>();
    private Code code;
    private int length;
    private String allData;

    public Group() {
        length = 0;
    }

    public void addData(LineInfo info) {
        oneLineList.add(info);
    }

    public void process() throws DataNotMatchCodingScheamException {

        StringBuilder sb = new StringBuilder();

        for (LineInfo in : oneLineList) {
            code = ParseCommand.getCodeObject(in);
            String data = listToString(code.getCode());
            length += code.getLength();
            sb.append(data);
        }
        allData = sb.toString();
    }

    private String listToString(List<String> l) {
        StringBuilder sb = new StringBuilder();
        for(String s : l){
            sb.append(s);
          }
          sb.append("\n");
          return sb.toString();
      }

	public String getAllData() {
        return allData;
    }

    public int getAllLength() {
        return length;
    }
    
    public String getName(){
    	return oneLineList.get(0).getName();
    }
}
